import model.sql as sql
import logging


def execute(call):
    session = sql.DBSession()
    try:
        for data in call(session):
            yield data
    except Exception as e:
        logging.error('receive error', exc_info=e)
    finally:
        session.close()